package com.qixiaobao.web.controller.statistic;

import com.qixiaobao.common.annotation.Log;
import com.qixiaobao.common.core.page.TableDataInfo;
import com.qixiaobao.common.enums.BusinessType;
import com.qixiaobao.common.exception.UtilException;
import com.qixiaobao.common.utils.easyExcel.EasyExcelUtil;
import com.qixiaobao.statistic.domain.dto.PersonStatisticDTO;
import com.qixiaobao.statistic.domain.vo.PersonStatisticVO;
import com.qixiaobao.statistic.service.IInsurePersonStatisticService;
import com.qixiaobao.web.controller.core.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description 投保人员统计
 * @Author yangxm
 * @Date 2025/7/8 15:02
 */
@RequestMapping("/statistic/insurePerson")
@RestController
public class InsurePersonStatisticController extends BaseController {

    @Autowired
    private IInsurePersonStatisticService insurePersonStatisticService;


    /**
     * @Description 投保人员统计 列表
     * @Author yangxm
     * @Date 2025/7/8 15:24
     * @param personStatisticDTO
     * @return com.qixiaobao.common.core.page.TableDataInfo
     */
    @GetMapping
    public TableDataInfo statistic(PersonStatisticDTO personStatisticDTO){
        //权限
        personStatisticDTO.setNoPermissionSupplyIdList(checkPermission());
        startPage();
        return getDataTable(insurePersonStatisticService.statistic(personStatisticDTO));
    }

    /**
     * @Description 投保人员统计 - 导出
     * @Author yangxm
     * @Date 2025/7/9 9:48
     * @param personStatisticDTO
     * @param response
     */
    @Log(title = "投保人员统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void statisticExport(PersonStatisticDTO personStatisticDTO, HttpServletResponse response){
        //权限
        personStatisticDTO.setNoPermissionSupplyIdList(checkPermission());
        List<PersonStatisticVO> list = insurePersonStatisticService.statistic(personStatisticDTO);
        String fileName = "投保人员统计";
        try {
            EasyExcelUtil.writeExcel(response, list, PersonStatisticVO.class, fileName, fileName);
        } catch (IOException e) {
            throw new UtilException("投保人员统计导出失败：" + e.getMessage());
        }
    }

}
